from SysHelp import SysHelp as sh
from DrissionPage import ChromiumPage
from DrissionPage import SessionPage
# from DrissionPage.easy_set import raise_when_ele_not_found
# from DrissionPage.easy_set import set_paths
from datetime import datetime
import time
import re

sh.clear_screen()
raise_when_ele_not_found = False
page = SessionPage()

s_name = 'xpath://div[@class="item-name"]/a/span'
s_view = 'xpath://div[@class="item-by"]/span[3]/span'

for page_num in range(1, 538):
    page.get(f'https://diy.szlcsc.com/p/projects?page={page_num}')

    e_names = page.s_eles(s_name)
    e_views = page.s_eles(s_view)

    if len(e_names) == len(e_views):
        for i in range(len(e_names)):
            print(f"{e_views[i].text}\t\t\t{e_names[i].text}")
            with open('collect.txt', 'a', encoding='utf-8') as file:
                file.write(f"{e_views[i].text}\t\t\t{e_names[i].text}\n")